var app = getApp()
Page({
  data: {
    address: "请选择",
    time: "请选择",
    date: "请选择",
    index: 0,
    addressList: [],
    loading: true,
    addressListStatus: false
  },
  onLoad: function (options) {
  },
  onShow: function (options) {
    app.fetchApi("https://cake.cindata.cn/address/getAddressByOpenId", (err, data) => {
      if (!data.errorCode) {
        if (data.length > 0) {
          this.setData({
            addressList: data,
            addressListStatus: false,
            loading: false
          })
        } else {
          this.setData({
            addressList: data,
            addressListStatus: true,
            loading: false
          })
        }
      }
    })
  },
  bindAddAddress: function (e) {
    wx.navigateTo({
      url: '/pages/address/address'
    })
  },
  editAddress: function (e) {
    wx.navigateTo({
      url: '/pages/address/address?id=' + e.currentTarget.dataset.id
    })
  },
  back: function (event) {
    // 防止个人中心点击地址返回
    if (getCurrentPages().length != 2) {
      app.globalData.addressId = event.currentTarget.dataset.id
      wx.navigateBack();
    }
  }
})
